<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    日期筛选
                </div>
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="dateRange" autocomplete="off" placeholder="点击选择日期">
                </div>


                <div class="layui-inline">
                    <input type="text" id="entityName" placeholder="顾客名称/房间号" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    是否退款
                </div>
                <div class="layui-inline">
                    <select id="type_select" lay-filter="type_select">
                        <option value="0" selected>未退款</option>
                        <option value="1">已退款</option>
                        <option value="9">强制退房</option>
                    </select>
                </div>
                <!-- 搜索按钮 -->
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" id="entity_search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="entityTable" lay-filter="entityTable"></table>
        </div>
    </div>
</div>

<script type="text/html" id="table_bar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </div>
</script>

<script src="../../js/jquery-1.8.3.min.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    //路径配置 - 手动填写
    var findPageURL = "/roomDeposit/findPage";
    var addURL = "/roomDeposit/add";
    var toUpdateURL = "/roomDeposit/findOne";
    var updateURL = "/roomDeposit/update";
    var deleteURL = "/roomDeposit/delete";

    var formTitle = "商品";
    //页面配置 - 不用填写
    var entityType = "";
    var entityURL = "";
    var entityId = "";

    //layui配置
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table', 'util', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , layer = layui.layer
            , util = layui.util
            , laydate = layui.laydate;
        laydate.render({
            elem: '#dateRange'
            , range: true
        });

        //监听搜索
        $("#entity_search").on('click', function (data) {
                //执行重载
                table.reload('entityTable', {
                    method: 'post'
                    , where: {
                        "cname": $("#entityName").val(),
                        'dateRange': $('#dateRange').val(),
                        "is_return": $("#type_select").val()
                    }
                    , page: {curr: 1}
                });
            }
        );

        //表格执行渲染
        table.render({
            elem: '#entityTable'
            , id: 'entityTable'
            , url: findPageURL
            , toolbar: true
            , totalRow: true
            , page: true
            , limits: [10, 20, 30, 50, 100]
            , cols: [[
                {field: 'cname', title: '顾客名称', width: 100, totalRowText: "合计"}
                , {field: 'rronumber', title: '订单号'}
                , {field: 'rname', title: '房间号', width: 100}
                , {field: 'iname', title: '收款人', width: 100}
                , {field: 'ename', title: '退款人', width: 100}
                , {field: 'price', title: '金额(元)', width: 100, totalRow: true}
                , {
                    field: 'ir', title: '是否退还', width: 130, templet: function (d) {
                        if (d.ir == "0") {
                            return "<span class=\"layui-badge\" >未退还</span>"
                        } else if (d.ir == "1") {
                            return "<span class=\"layui-badge layui-bg-green\" >已退还</span>"
                        } else if (d.ir == "9") {
                            return "<span class=\"layui-badge layui-bg-green\" >强制退房</span>"
                        }
                    }
                }
                , {
                    field: 'rrogmt', title: '收款时间',
                    templet: function (d) {
                        return util.toDateString(d.rrogmt, 'yyyy-MM-dd HH:mm:ss')
                    }
                }
                , {
                    fixed: 'right', title: '操作', align: 'center', templet: function (d) {
                        if (d.ir == "9") {
                            return '<a class="layui-btn layui-btn-xs layui-bg-red" lay-event="edit">退押金</a>'
                        }
                        return "";
                    }
                }
            ]]
            , where: {
                "cname": $("#entityName").val(),
                'dateRange': $('#dateRange').val(),
                "is_return": $("#type_select").val()
            }
        });

        //添加操作
        var $ = layui.$, active = {
            add: function () {
                entityType = "add";
                entityURL = addURL;
                layer.open({
                    type: 2
                    , title: "添加" + formTitle + "信息"
                    , content: 'form.html'
                    , maxmin: true
                    , area: ['400px', '500px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#entity-submit");
                        submit.click();
                    }
                });
            }
        };

        //监听行工具事件
        table.on('tool(entityTable)', function (obj) { //注：tool 是工具条事件名，zq_table 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (layEvent) {
                case 'edit':
                    layer.confirm('您确定退还房间号为：' + data.rname + ' 的押金吗？', function (index) {
                        //向服务端发送删除指令，在这里使用Ajax异步
                        $.post("/roomDeposit/returnById", {"id": data.id}, function (ret) {
                            layer.msg(ret.msg, {icon: ret.icon, time: 1500});
                            layer.close(index);
                            $(".layui-laypage-btn").click();//点击分页刷新当前页
                        });
                    });
                    break;
            }
        });
        //必备
        $('.layui-btn.layuiadmin-btn-role').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>

